﻿///////////////////////////////////////////////////////////////////////////////
//
// This file is part of the BassDrop project
//   https://code.google.com/p/bass-drop/
//
//
// Creator:	Gergely Krajcsovszki (krajcsovszkig@hotmail.com)
// Date:	2014-01-20 13:25
//
//
// Copyright © 2013-2014. Gergely Krajcsovszki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
///////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BassDrop.Core.Common.Services
{
	/// <summary>
	/// Interface for globally available cryptographic functions
	/// </summary>
	public interface ICryptoProvider
	{
		/// <summary>
		/// Symmetrically encrypts the passed string with the passed parameters
		/// and returns a base64 representation of the resulting cyphertext.
		/// </summary>
		/// <param name="plainText">the text to encrypt</param>
		/// <param name="password">the password to use for encryption</param>
		/// <param name="salt">the salt to use for the encryption - if null or left out, no salting is done</param>
		/// <param name="strength">the arbitrary strength of the encryption - usually means the number of iterations</param>
		/// <returns></returns>
		string Encrypt( string plainText, string password, string salt = null, CryptoStrength strength = CryptoStrength.Normal );

		/// <summary>
		/// Decrypts the passed cyphertext using the passed parameters
		/// (as encrypted by the Encrypt method - symmetrically with the passed parameters and encoded in base64)
		/// and returns the resulting plaintext.
		/// </summary>
		/// <param name="cipherText">the encrypted text to decrypt in base64 encoding</param>
		/// <param name="password">the password to use for encryption</param>
		/// <param name="salt">the salt to use for the encryption - if null or left out, no salting is done</param>
		/// <returns></returns>
		string Decrypt( string cipherText, string password, string salt = null );

		/// <summary>
		/// Symmetrically encrypts the passed string using the operating system's own facilities and returns a base64 representation of
		/// the resulting cyphertext.
		/// This does not need a password, but the encrypted data can only be decrypted later on this computer by this same user.
		/// </summary>
		/// <param name="plainText">the text to encrypt</param>
		/// <returns></returns>
		string EncryptLocal( string plainText );

		/// <summary>
		/// Decrypts the passed cyphertext (as encrypted by the EncryptLocal method - symmetrically on this computer 
		/// by this same user and encoded in base64) and returns the resulting plaintext.
		/// </summary>
		/// <param name="cipherText">the encrypted text to decrypt in base64 encoding</param>
		/// <returns></returns>
		string DecryptLocal( string cipherText );

		// TODO: helperek, pl. kulcsgenerálás, stb.
	}

	/// <summary>
	/// The strength of an encryption
	/// </summary>
	public enum CryptoStrength
	{
		/// <summary>
		/// Fast but easy to crack encryption, use only to avoid explicitly showing plaintext
		/// </summary>
		Basic,
		/// <summary>
		/// Normal encryption, use for not too secret data or when using a strong one is pointless,
		/// for example when the parameters used for the encryption cannot themselves be properly
		/// secured.
		/// </summary>
		Normal,
		/// <summary>
		/// Strong encryption, safe enough in most cases
		/// </summary>
		Strong,
		/// <summary>
		/// Super strong encryption for super secret data or paranoid users.
		/// Might take quite a while to process.
		/// </summary>
		UltraStrong
	}
}
